package com.dq.domain.goods.centre;


import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;

import com.dq.domain.goods.Goods;
import com.dq.domain.goods.Product;
import com.dq.domain.sys.section.SysSection;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.validation.constraints.NotNull;

/**
 * @author cf
 */
@Data
@Entity
@ApiModel("商品门店关联表")
public class OrgGoodsCentre extends BaseEntity implements VO.ToVO {
    @ApiModelProperty("关联goods, 便于搜索")
    @ManyToOne
    public Goods goods;
    @NotNull
    @ApiModelProperty("关联product")
    @ManyToOne
    @NotNull
    public Product product;

    @ApiModelProperty("关联门店")
    @ManyToOne
    @NotNull
    public SysSection org;

    @ApiModelProperty("库存数")
    @NotNull
    public Long count;

    @Data
    @ApiModel(value = "视图")
    public static class Vo implements VO {
        public Long id;
        @ApiModelProperty(value = "商品信息")
        public Long goodsId;
        public String goodsName;
        @ApiModelProperty(value = "product信息")
        public Long productId;

        @ApiModelProperty(value = "门店信息")
        public Long orgId;
        public String orgName;

        @ApiModelProperty("库存数")
        public Long count;
    }
    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.getId();
        vo.goodsId = this.getGoods() == null ? null : this.getGoods().getId();
        vo.goodsName = this.getGoods() == null ? "" : this.getGoods().getGoodsName();
        vo.productId = this.getProduct() == null ? null : this.getProduct().getId();
        vo.orgId = this.getOrg() == null ? null : this.getOrg().getId();
        vo.orgName = this.getOrg() == null ? "" : this.getOrg().getSimpleName();
        vo.count = fmt(this.getCount());
        return vo;
    }

}
